
//http://Localhost:8070/Server/,Loclhost
package com.example.controller;
import com.example.Utils.lookUpUtils;
import com.example.pojo.Result;
import com.example.pojo.ThreeList;
import com.example.pojo.repairBookPojo;
import com.example.service.repairBookService;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
 * ClassName:repairBook
 * Description:
 *
 */
@RestController
@Slf4j
public class repairBookController {
    @Autowired
    private repairBookService repairBookService;
    @PostMapping("/repairStepList")
    public Result list(@RequestBody repairBookPojo repairBook){
        List<repairBookPojo> repairList = repairBookService.list(repairBook.getWorkshop(),repairBook.getTaksName(),repairBook.getLanguageS());
        return Result.success(repairList);
    }
    @PostMapping("/TreeList")
    public Result TreeList(){
        List<ThreeList> TreeList = repairBookService.TreeList();
        return Result.success(TreeList);
    }
    //用在了编辑步骤中，因为转换数据格式有异常（）数据中的字符串没有安装utf-8的格式解析，因此这次操作用过了两个接口完成。
    @PutMapping("/repairModifySteps")//
    public Result repairModifySteps(@RequestPart("tableDataTemp") String tableDataTempJson,@RequestPart("fileListV") List<MultipartFile> fileListV) throws JsonProcessingException {
        repairBookService.repairModifySteps(tableDataTempJson,fileListV);
        return Result.success();
    }
    @PutMapping("/repairModifyStepsString")
    public Result repairModifyStepsString(@RequestBody repairBookPojo repairBookPojo){
        repairBookService.repairModifyString(repairBookPojo);
        return Result.success();
    }
    /*
    * 通过ID，查询某一个字段中的值，返回在通用结果中的是一个字符串
    */
    @PostMapping("/ListID")
    public Result lookupId(@RequestBody lookUpUtils lookR){
        String fieldResult = repairBookService.lookupId(lookR);
        return Result.success(fieldResult);
    }

    /*
    * 按照ID，修改某一个字段的值
    **/
    @PutMapping("/repairModifyById")
    public Result repairModifyById(@RequestBody repairBookPojo repairBookPojo){
        repairBookService.repairModifyById(repairBookPojo);
        return Result.success();
    }
    /*
     * 插入一个新的步骤
     **/
    @PostMapping("/addStep")
    public Result addStep(@RequestBody repairBookPojo repairBookPojo){
        repairBookService.addStep(repairBookPojo);
        return Result.success();
    }
    /*接收前端的删除命令，对操作步骤进行删除*/
    @DeleteMapping("/repairDelete")
    public Result repairDelete(@RequestBody repairBookPojo repairBookPojo){
        //根据id，删除本行。
        repairBookService.repairDelete(repairBookPojo);
        return Result.success();
    }
    /*前端输入一组数据，进行添加到数据库中*/
    @PostMapping("/addFile")
    public Result addFile(@RequestBody List<repairBookPojo> repairBookPojos){
        log.info(repairBookPojos.toString());
        repairBookService.addFile(repairBookPojos);
        return Result.success();
    }
    @PutMapping("/editUseOrder")
    /*用在前端调整作业指导书步骤后，进行数据修改保存*/
    public Result editUseOrder(@RequestBody List<repairBookPojo> repairBookPojos){
//        repairBookService.editUseOrder(repairBookPojos);
        return Result.success();
    }

}
